<?php 

/*
 * Following code will create a new pemesanan row
 * All pemesanan details are read from HTTP Post Request
 */

/* array for JSON response */
$response = array();

/* check for required fields */

if (isset($_POST['id_pemesanan']) && isset($_POST['nama_file']) ) {

    $id_pemesanan = $_POST['id_pemesanan'];
    $nama_file = $_POST['nama_file'];
    
    require_once __DIR__ . '/db_connect.php';

    $db = new DB_CONNECT();
	
    $result = mysql_query("INSERT INTO bukti_pembayaran(id_pemesanan, foto) VALUES ($id_pemesanan,'$nama_file')");

    /* check if row inserted or not */
    if ($result) {
        /* successfully inserted into database */
        $response["success"] = 1;
        $response["message"] = "Bukti Pembayaran successfully created.";

        /* echoing JSON response */
        echo json_encode($response);
$email = "useruploadedimage@gmail.com";
$message  = 
"ID Pemesanan Anda : ".$id_pemesanan."
Uploaded File : ".$nama_file."
";      

	$subject = "Detail Pemesanan Hanjuang";
	mail($email, $subject,$message, "From:" . "hanjuang_igpersada@yahoo.com");
		/* echo "<hr>Thank you for using our mail form yo!"; */

    } else {
        /* failed to insert row */
        $response["success"] = 0;
        $response["message"] = "Oops! An error occurred.";
        
        /* echoing JSON response */
        echo json_encode($response);
    }
} else {    
    $response["success"] = 0;
    $response["message"] = "Required field(s) is missing";
	
    echo json_encode($response);
}
?>